/************************************************************************************/
/*  Program name CAPFNDIMP_REQUEST_SETS_START.sql                                   */
/*  Creater:  Chan Billy Ka Keung (PCCW - UniHub)                                   */
/*************   History   *************************                                */
/* 01 FEB, 2006   CHAN Billy Ka Keung         First created                         */
/************************************************************************************/

SET SERVEROUTPUT ON SIZE 1000000;
--ALTER TRIGGER FND_REQUEST_SETS_CT1 DISABLE;

DECLARE

	lv_Prog_ID		VARCHAR2(100) 	:=	'CAPFNDIMP_REQUEST_SETS_START';

	lv_Scc_Count	NUMBER			:=	0;
	lv_Err_Count	NUMBER			:=	0;
	lv_Err_Msg		VARCHAR2(500)	:=	'No Error';

	lv_Next_Seq_ID	NUMBER;

BEGIN

	BEGIN
		UPDATE	FND_REQUEST_SETS
		SET		Start_Stage		=	CAPBRIMP_MAPPING.GetRequestSetStageIDMapping(Start_Stage)
		WHERE	Start_Stage		IS	NOT NULL
		AND		Request_Set_ID	IN
					(
						SELECT	Request_Set_ID_N
						FROM	CRST_FND_REQUEST_SETS_MAP
					);

		lv_Scc_Count	:=	lv_Scc_Count + 1;
	EXCEPTION
		WHEN OTHERS THEN
			DBMS_OUTPUT.Put_Line(SQLERRM);
			lv_Err_Count	:=	lv_Err_Count + 1;
	END;

	IF lv_Err_Count	>	0	THEN
		ROLLBACK;
	END IF;

	INSERT INTO CAPCNV_LOG(
		PROG_ID,
		PROCESS_DATE,
		RECORD_PROCESSED,
		RECORD_REJECTED,
		RECORD_EXTRACTED,
		ERR_MSG
		)
	VALUES (
		lv_Prog_ID,
		SYSDATE,
		lv_Scc_Count,
		lv_Err_Count,
		lv_Scc_Count - lv_Err_Count,
		lv_Err_Msg
	);

	COMMIT;
END;
/
--ALTER TRIGGER FND_REQUEST_SETS_CT1 ENABLE;
